﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

using Newtonsoft.Json;

using Happy.Query;

namespace Happy.Web.Mvc.ExtJs
{
    /// <summary>
    /// 动态查询控制器，面向树形结构。
    /// </summary>
    public abstract class DynamicTreeQueryController<TDynamicQueryService> : DynamicQueryController<TDynamicQueryService>
        where TDynamicQueryService : IDynamicQueryService
    {
        /// <summary>
        /// 获取树形数据，面向树。
        /// </summary>
        public ActionResult ReadNode(Guid node)
        {
            var query = DynamicQueryObject.Create("ParentId = @0", new object[] { node });

            var items = this.QueryService.Fetch(query);

            return this.FetchResult(items);
        }

        /// <summary>
        /// 获取树形数据，面向树。
        /// </summary>
        public ActionResult ReadTree(Guid node)
        {
            var query = DynamicQueryObject.Create("ParentId = @0", new object[] { node });

            var items = this.QueryService.Fetch(query);

            return this.FetchResult(items);
        }
    }
}
